package o.gwtp.editor.client.main;

import o.gwtp.editor.client.main.MainPresenter.MyView;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewImpl;

/**
 * @author Christian Goudreau
 */
public class MainView extends ViewImpl implements MyView {
  private static Binder uiBinder = GWT.create(Binder.class);

  interface Binder extends UiBinder<Widget, MainView> {
  }

  private final Widget widget;

  @UiField
  SimplePanel navigationPanel;
  @UiField
  SimplePanel contentPanel;

  public MainView() {
    widget = uiBinder.createAndBindUi(this);
  }

  @Override
  public Widget asWidget() {
    return widget;
  }

  @Override
  public void setInSlot(Object slot, Widget content) {
    if (slot == MainPresenter.CONTENT_SLOT) {
      contentPanel.clear();
      contentPanel.add(content);
    } else if (slot == MainPresenter.NAVIGATION_SLOT) {
      navigationPanel.clear();
      navigationPanel.add(content);
    } else {
      super.setInSlot(slot, content);
    }
  }
}
